/*
 * @Author: hx 2542123711@QQ.com
 * @Date: 2024-11-22 17:22:39
 * @LastEditors: hx 2542123711@QQ.com
 * @LastEditTime: 2024-11-22 18:23:15
 * @FilePath: /class_process-communication/ShareMemery/processa.cc
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include<iostream>
#include<sys/ipc.h>
#include<sys/shm.h>
#include"shm.hpp"

using namespace std;

//processa 创建共享内存，并且发送数据
int main()
{
    //1.创建共享内存
    int shmid = Createshmid();

    //2.processa挂起shmid共享内存区
    char* shmaddress = (char*)shmat(shmid, nullptr, 0);

    //3.开始通信 -> processa接受数据（读）
    while(true)
    {
        cout << "client say@ " << shmaddress << endl;
        sleep(1);
    }

    //4.解除挂起共享内存
    shmdt(shmaddress);  

    //5.释放共享内存
    int m = shmctl(shmid, IPC_RMID, nullptr);

    return 0;
}